<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>题库管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>组件</cite></a>
    <a><cite>数据表格</cite></a>
    <a><cite>题库管理</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-header"></div>
        <div class="layui-card-body">

          <div class="test-table-reload-btn layui-form-item" style="margin-bottom: 10px;">
            姓名：
            <div class="layui-inline">
              <input class="layui-input" name="name" autocomplete="off">
            </div>
            是否通过
            <div class="layui-inline layui-form">
              <select name="isPass">
                <option value="">--请选择--</option>
                <option value="0">未通过</option>
                <option value="1">通过</option>
              </select>
            </div>
            <button class="layui-btn" data-type="reload">搜索</button>
          </div>

          <table class="layui-hide" id="table-trainResult" lay-filter="table-trainResult-toolbar"></table>

          <script type="text/html" id="table-result-isPass">
            {{#  if(d.isPass == 0){ }}
            <span class="layui-badge layui-bg-gray">未通过</span>
            {{#  } else{ }}
            <span class="layui-badge layui-bg-blue">通过</span>
            {{#  } }}
          </script>

        </div>
      </div>
    </div>
  </div>
</div>

<script src="../../../layuiadmin/layui/layui.js"></script>
<script>
    editData = [];
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function(){
        var admin = layui.admin
            ,table = layui.table
            ,$ = layui.$
            ,form = layui.form;

        var editData = parent.editData;
        console.log(editData);

        table.render({
            elem: '#table-trainResult'
            ,url: '/admin/result/results'
            ,page: true
            ,limit : 10
            ,limits: [10,30,60,90]
            ,loading: true   //开启翻页加载动画
            ,toolbar: '#table-trainResult-toolbar'   //开启toolbar
            //,height: 'full-100' //高度最大自适应
            ,cols: [[
                {field:'name',  title: '姓名' }
                ,{field:'company',  title: '公司'}
                ,{field:'score',  title: '成绩'}
                ,{field:'resultCount',  title: '题目数量' }
                ,{field:'isPass',  title: '是否通过' ,templet: '#table-result-isPass'}
                ,{field:'useTime',  title: '耗时' }
                ,{field:'createTime',  title: '提交时间' }
            ]]

        });

        table.reload('table-trainResult', {
            page: {
                curr: 1 //重新从第 1 页开始
            }
            ,where: {"trainId":editData.trainId}
        });

        //搜索
        var active = {
            reload: function(){
                console.log($('[name=isPass]').val());
                //执行重载
                table.reload('table-trainResult', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        name: $('[name=name]').val(),
                        isPass:$('[name=isPass]').val()
                    }
                });
            }
        };

        $('.test-table-reload-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>
</body>
</html>